using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace XNADemo
{
    public class Core : Microsoft.Xna.Framework.Game
    {
        //-----------------------------------------------------------------------
        private GraphicsDeviceManager graphics;
        
        public static SpriteBatch spriteBatch;
        public static SpriteFont Font;

        SWF.Runtime.Clip clip;

        public Core()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            graphics.PreferMultiSampling = true;
        }

        protected override void Initialize()
        {
            base.Initialize();

            ResourceContentManager r = new ResourceContentManager(this.Services, SWF.Resource.ResourceManager);

            SWF.SWFMain.CreateContext(GraphicsDevice, r.Load<Effect>("SWF8"));

            clip = new SWF.Runtime.Clip();
            clip.Load("../../../../../../Assets/Title.swf");

            IsMouseVisible = true;
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Font = Content.Load<SpriteFont>("NormalFont");
        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                clip.Stop();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.B))
            {
                for (uint i = 2; i < 24; ++i)
                {
                    SWF.Debug.ShapeRenderControl.SetEnabled(i, false);
                }
            }

            clip.Update(gameTime);

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            clip.Render();

            base.Draw(gameTime);
        }
    }
}
